package com.bkhc.product.api;

import com.bkhc.common.annotation.ApiOperation;
import com.bkhc.common.annotation.ApiPackage;
import com.bkhc.common.annotation.AuditLog;
import com.bkhc.common.enu.OperationEnum;
import com.bkhc.common.util.response.ResultJson;
import com.bkhc.product.entity.Goods;
import com.bkhc.product.entity.GoodsSpec;
import com.bkhc.product.entity.Spec;
import com.bkhc.product.service.GoodsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pcq
 * @date 2021/6/20 17:57
 */
@RestController
@RequestMapping("/goods")
@Api("产品实例服务")
@ApiPackage(code="goods-api",name="产品实例服务",description = "后台产品实例服务维护操作接口")
public class GoodsController extends CommonController{
    @Autowired
    private GoodsService serivce;

    @ApiOperation(code="queryGoods",name="查询实例产品",description = "查询实例产品",type = "common")
    @AuditLog(object="Goods",operation = "查询实例产品",type = OperationEnum.query)
    @RequestMapping(path = "/list/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public ResultJson<?> queryGoods(@RequestBody(required=false) Goods goods, @PathVariable(name="pageNum") int pageIndex, @PathVariable(name="pageSize") int pageSize) {
        ResultJson<?> res = serivce.getGoods(goods, pageIndex, pageSize);
        return res;
    }

    @ApiOperation(code="udpateGoods",name="修改实例产品规格值",description = "修改实例产品规格值")
    @AuditLog(object="Goods",operation = "修改实例产品规格值",type = OperationEnum.update)
    @RequestMapping(path = "/spec/update",method = RequestMethod.POST)
    public ResultJson<?> updateProductInstanceSpec(@RequestBody(required=false) List<GoodsSpec> goodsSpecs) {
        ResultJson<?> res = serivce.updateGoodsSpec(goodsSpecs);
        return res;
    }

    @ApiOperation(code="addGoods",name="增加商品",description = "增加商品")
    @AuditLog(object="Goods",operation = "增加商品",type = OperationEnum.update)
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    public ResultJson<?> addGoods(@RequestBody(required=false) Goods goods) {
        ResultJson<?> res = serivce.addGoods(goods);
        return res;
    }

    @ApiOperation(code="deleteProductInstance",name="删除实例产品",description = "删除实例产品")
    @AuditLog(object="ProductInstance",operation = "删除实例产品",type = OperationEnum.delete)
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public ResultJson<?> deleteProductInstance(@RequestParam(name="goodsCode") String goodsCode) {
        ResultJson<?> res = serivce.deleteGoods(goodsCode);
        return res;
    }
    @ApiOperation(code="getGoodsByProduct",name="查询实例产品",description = "查询实例产品",type="common")
    @AuditLog(object="Goods",operation = "查询实例产品",type = OperationEnum.query)
    @RequestMapping(path = "/getGoodsByProduct",method = RequestMethod.POST)
    public ResultJson<?> getGoodsByProduct(@RequestParam(name="productCode") String productCode) {
        ResultJson<?> res = serivce.getGoodsByProduct(productCode);
        return res;
    }

    @ApiOperation(code="getSpecsByGoodsList",name="查询商品集合的规格",description = "查询商品集合的规格",type="common")
    @AuditLog(object="Goods",operation = "查询商品集合的规格",type = OperationEnum.query)
    @RequestMapping(path = "/getSpecsByGoodsList",method = RequestMethod.POST)
    public  List<GoodsSpec> getGoodsByProduct(@RequestBody List<String> goodsList) {
        List<GoodsSpec> res = serivce.getSpecsByGoodsList(goodsList);
        return res;
    }


}
